package com.IR.order.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.IR.shop.mapper.OrderdetailMapper;
import com.IR.shop.mapper.OrdersMapper;
import com.IR.shop.po.Orderdetail;
import com.IR.shop.po.OrderdetailExample;
import com.IR.shop.po.Orders;
import com.IR.shop.po.OrdersExample;

@Service
public class BOrderBiz {
	@Resource(name="ordersmapper")
	public OrdersMapper mapper1;
	@Resource(name="orderdetailmapper")
	public OrderdetailMapper mapper2;
	private Orders orders;
	private Orderdetail orderdetail;
	private List<Orders> list1;
	private List<Orderdetail> list2;
	public Orders getOrders() {
		return orders;
	}
	public void setOrders(Orders orders) {
		this.orders = orders;
	}
	public Orderdetail getOrderdetail() {
		return orderdetail;
	}
	public void setOrderdetail(Orderdetail orderdetail) {
		this.orderdetail = orderdetail;
	}
	public List<Orders> getList1() {
		return list1;
	}
	public void setList1(List<Orders> list1) {
		this.list1 = list1;
	}
	public List<Orderdetail> getList2() {
		return list2;
	}
	public void setList2(List<Orderdetail> list2) {
		this.list2 = list2;
	}
	public List<Orders> showOrderAll(){
		OrdersExample example=new OrdersExample();
		return mapper1.selectByExample(example);		
	}
	public List<Orders> showOrderPage(int pagenow,int pagesize){
		OrdersExample example=new OrdersExample();
		int start=(pagenow-1)*pagesize;
		example.setOffset(start);
		example.setLimit(pagesize);
		return mapper1.selectByExample(example);
	}
	public List<Orders> showOrderPage2(Long userid){
		OrdersExample example=new OrdersExample();
		int pagenow=1;
		int pagesize=20;
		int start=(pagenow-1)*pagesize;
		example.setOffset(start);
		example.setLimit(pagesize);
		OrdersExample.Criteria c=example.createCriteria();
		c.andUseridEqualTo(userid);
		c.andOrderstateNotEqualTo(7);
		return mapper1.selectByExample(example);
	}
	public List<Orderdetail> showOrderId(Long orderid){
		OrderdetailExample example=new OrderdetailExample();
		OrderdetailExample.Criteria c=example.createCriteria();
		c.andOrderidEqualTo(orderid);
		return mapper2.selectByExample(example);
	}
	public Orders showOrderId2(Long orderid){
		return mapper1.selectByPrimaryKey(orderid);
	}
	public List<Orders> showOrderState(Long userid,int orderstate){
		OrdersExample example=new OrdersExample();
		OrdersExample.Criteria c=example.createCriteria();
		int pagenow=1;
		int pagesize=20;
		int start=(pagenow-1)*pagesize;
		example.setOffset(start);
		example.setLimit(pagesize);
		c.andUseridEqualTo(userid);
		c.andOrderstateEqualTo(orderstate);
		return mapper1.selectByExample(example);
	}
	public List<Orders> showOrderState2(int orderstate,int pagenow,int pagesize){
		OrdersExample example=new OrdersExample();
		OrdersExample.Criteria c=example.createCriteria();
		/*int pagenow=1;
		int pagesize=20;*/
		int start=(pagenow-1)*pagesize;
		example.setOffset(start);
		example.setLimit(pagesize);
		if(orderstate==4) {
			List<Integer> list=new ArrayList<Integer>();
			list.add(4);
			list.add(7);
			c.andOrderstateIn(list);
		}else {
			c.andOrderstateEqualTo(orderstate);
		}
		
		return mapper1.selectByExample(example);
		
	}
}
